﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Entity;
using Microsoft.VisualBasic.FileIO;
using System.Windows.Forms;

namespace DAL
{
    public class SettingsService
    {

        #region 查询工艺规范数据库内全部内容
        public List<Settings> GetAll()
        {
            string sql = "select * from Settings";
            SqlDataReader objReader = SQLHelper.GetReader(sql);
            List <Settings> list = new List<Settings>();
            try
            {
                while (objReader.Read())
                {
                    list.Add(new Settings()
                    {
 
                        MultistageId = objReader["MultistageId"].ToString() == "" ? 0 : Convert.ToInt32(objReader["MultistageId"]),
                        SettingsId = objReader["SettingsId"].ToString() == "" ? 0 : Convert.ToInt32(objReader["SettingsId"]),
                        SettingsName = objReader["SettingsName"].ToString() == "" ? "0" : Convert.ToString(objReader["SettingsName"]),
                        FastenerId = objReader["FastenerId"].ToString() == "" ? "0" : Convert.ToString(objReader["FastenerId"]),
                        LayerStackId = objReader["LayerStackId"].ToString() == "" ? 0 : Convert.ToInt32(objReader["LayerStackId"]),
                        TargetVelo1 = objReader["TargetVelo1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetVelo1"]),
                        TargetVelo2 = objReader["TargetVelo2"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetVelo2"]),
                        TargetVelo3 = objReader["TargetVelo3"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetVelo3"]),
                        TargetVelo4 = objReader["TargetVelo4"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetVelo4"]),
                        TargetVelo5 = objReader["TargetVelo5"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetVelo5"]),
                        RotationalSpeed1 = objReader["RotationalSpeed1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["RotationalSpeed1"]),
                        RotationalSpeed2 = objReader["RotationalSpeed2"].ToString() == "" ? 0 : Convert.ToSingle(objReader["RotationalSpeed2"]),
                        RotationalSpeed3 = objReader["RotationalSpeed3"].ToString() == "" ? 0 : Convert.ToSingle(objReader["RotationalSpeed3"]),
                        RotationalSpeed4 = objReader["RotationalSpeed4"].ToString() == "" ? 0 : Convert.ToSingle(objReader["RotationalSpeed4"]),
                        RotationalSpeed5 = objReader["RotationalSpeed5"].ToString() == "" ? 0 : Convert.ToSingle(objReader["RotationalSpeed5"]),
                        TargetPos1 = objReader["TargetPos1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetPos1"]),
                        TargetPos2 = objReader["TargetPos2"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetPos2"]),
                        TargetPos3 = objReader["TargetPos3"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetPos3"]),
                        TargetPos4 = objReader["TargetPos4"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetPos4"]),
                        TargetPos5 = objReader["TargetPos5"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetPos5"]),
                        Bias1 = objReader["Bias1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Bias1"]),
                        TargetDownforce1 = objReader["TargetDownforce1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetDownforce1"]),
                        TargetTorque1 = objReader["TargetTorque1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetTorque1"]),
                        T1 = objReader["T1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["T1"]),
                        FeedVelo1 = objReader["FeedVelo1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["FeedVelo1"]),
                        FeedVelo2 = objReader["FeedVelo2"].ToString() == "" ? 0 : Convert.ToSingle(objReader["FeedVelo2"]),
                        MaxFeedingTime = objReader["MaxFeedingTime"].ToString() == "" ? 0 : Convert.ToInt32(objReader["MaxFeedingTime"]),
                        MaxPrePressingTime = objReader["MaxPrePressingTime"].ToString() == "" ? 0 : Convert.ToInt32(objReader["MaxPrePressingTime"]),
                        MaxRivetingTime = objReader["MaxRivetingTime"].ToString() == "" ? 0 : Convert.ToInt32(objReader["MaxRivetingTime"]),
                        UPLimitPos = objReader["UPLimitPos"].ToString() == "" ? 0 : Convert.ToSingle(objReader["UPLimitPos"]),
                        StopTorque = objReader["StopTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["StopTorque"]),
                        Constant_Downforce1 = objReader["Constant_Downforce1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Constant_Downforce1"]),
                        PressTime = objReader["PressTime"].ToString() == "" ? 0 : Convert.ToInt32(objReader["PressTime"]),
                        TargetVelo6 = objReader["TargetVelo6"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetVelo6"]),
                        TargetPos6 = objReader["TargetPos6"].ToString() == "" ? 0 : Convert.ToSingle(objReader["TargetPos6"]),
                        FeedPos1 = objReader["FeedPos1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["FeedPos1"]),
                        FSR_FeedPos1 = objReader["FSR_FeedPos1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["FSR_FeedPos1"]),
                        FSR_ContactPos1 = objReader["FSR_ContactPos1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["FSR_ContactPos1"]),
                        UpperPos1 = objReader["UpperPos1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["UpperPos1"]),
                        LowerPos1 = objReader["LowerPos1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["LowerPos1"]),
                        StopPressure1 = objReader["StopPressure1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["StopPressure1"]),
                        Pre_Downforce1 = objReader["Pre_Downforce1"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Pre_Downforce1"]),
                        PrePressureSetValue = objReader["PrePressureSetValue"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressureSetValue"]),
                        FastenerName = objReader["FastenerName"].ToString() == "" ? "0" : Convert.ToString(objReader["FastenerName"]),
                        Para_D = objReader["Para_D"].ToString() == "" ? "0" : Convert.ToString(objReader["Para_D"]),
                        Para_P = objReader["Para_P"].ToString() == "" ? "0" : Convert.ToString(objReader["Para_P"]),
                        Para_H = objReader["Para_H"].ToString() == "" ? "0" : Convert.ToString(objReader["Para_H"]),
                        Para_L = objReader["Para_L"].ToString() == "" ? "0" : Convert.ToString(objReader["Para_L"]),
                        LayerStackName = objReader["LayerStackName"].ToString() == "" ? "0" : Convert.ToString(objReader["LayerStackName"]),
                        Material1 = objReader["Material1"].ToString() == "" ? "0" : Convert.ToString(objReader["Material1"]),
                        Thickness1 = objReader["Thickness1"].ToString() == "" ? "0" : Convert.ToString(objReader["Thickness1"]),
                        Material2 = objReader["Material2"].ToString() == "" ? "0" : Convert.ToString(objReader["Material2"]),
                        Thickness2 = objReader["Thickness2"].ToString() == "" ? "0" : Convert.ToString(objReader["Thickness2"]),
                        PressConfirmed = objReader["PressConfirmed"].ToString() == "" ? false: Convert.ToBoolean(objReader["PressConfirmed"]),
                        StopTorqueConfirmed = objReader["StopTorqueConfirmed"].ToString() == "" ? false : Convert.ToBoolean(objReader["StopTorqueConfirmed"]),
 
                        PrePressHighPosition = objReader["PrePressHighPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressHighPosition"]),
                        PrePressHighSpeed = objReader["PrePressHighSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressHighSpeed"]),
                        PrePressLowPosition = objReader["PrePressLowPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressLowPosition"]),
                        PrePressLowSpeed = objReader["PrePressLowSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressLowSpeed"]),
                        PrePressTouchForce = objReader["PrePressTouchForce"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressTouchForce"]),
                        PrePressForce = objReader["PrePressForce"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressForce"]),
                        Rivet1Force = objReader["Rivet1Force"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1Force"]),
                        Rivet1ForceP = objReader["Rivet1ForceP"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1ForceP"]),
                        Rivet1ForceI = objReader["Rivet1ForceI"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1ForceI"]),
                        Rivet1RotationalSpeed = objReader["Rivet1RotationalSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1RotationalSpeed"]),
                        Rivet1RotationalACCTime = objReader["Rivet1RotationalACCTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1RotationalACCTime"]),
                        Rivet1RotationalDECTime = objReader["Rivet1RotationalDECTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1RotationalDECTime"]),
                        Rivet1OKUpPosition = objReader["Rivet1OKUpPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKUpPosition"]),
                        Rivet1OKDownPosition = objReader["Rivet1OKDownPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKDownPosition"]),
                        Rivet1OKSpeedJudgment = objReader["Rivet1OKSpeedJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKSpeedJudgment"]),
                        Rivet1OKSpeed = objReader["Rivet1OKSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKSpeed"]),
                        Rivet1OKPositionVariationJudgment = objReader["Rivet1OKPositionVariationJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKPositionVariationJudgment"]),
                        Rivet1OKPositionVariation = objReader["Rivet1OKPositionVariation"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKPositionVariation"]),
                        Rivet1OKPositionVariationSamplintTime = objReader["Rivet1OKPositionVariationSamplintTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKPositionVariationSamplintTime"]),
                        Rivet1OKTorqueJudgment = objReader["Rivet1OKTorqueJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKTorqueJudgment"]),
                        Rivet1OKTorque = objReader["Rivet1OKTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKTorque"]),
                        Rivet1OKPositionJudgment = objReader["Rivet1OKPositionJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKPositionJudgment"]),
                        Rivet1OKPosition = objReader["Rivet1OKPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKPosition"]),
                        Rivet1OverTime = objReader["Rivet1OverTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OverTime"]),
                        Rivet1MaxSpeed = objReader["Rivet1MaxSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1MaxSpeed"]),
                        Rivet2Force = objReader["Rivet2Force"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2Force"]),
                        Rivet2ForceP = objReader["Rivet2ForceP"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2ForceP"]),
                        Rivet2ForceI = objReader["Rivet2ForceI"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2ForceI"]),
                        Rivet2RotationalSpeed = objReader["Rivet2RotationalSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2RotationalSpeed"]),
                        Rivet2RotationalACCTime = objReader["Rivet2RotationalACCTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2RotationalACCTime"]),
                        Rivet2RotationalDECTime = objReader["Rivet2RotationalDECTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2RotationalDECTime"]),
                        Rivet2OKUpPosition = objReader["Rivet2OKUpPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKUpPosition"]),
                        Rivet2OKDownPosition = objReader["Rivet2OKDownPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKDownPosition"]),
                        Rivet2OKSpeedJudgment = objReader["Rivet2OKSpeedJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKSpeedJudgment"]),
                        Rivet2OKSpeed = objReader["Rivet2OKSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKSpeed"]),
                        Rivet2OKPositionVariationJudgment = objReader["Rivet2OKPositionVariationJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKPositionVariationJudgment"]),
                        Rivet2OKPositionVariation = objReader["Rivet2OKPositionVariation"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKPositionVariation"]),
                        Rivet2OKPositionVariationSamplintTime = objReader["Rivet2OKPositionVariationSamplintTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKPositionVariationSamplintTime"]),
                        Rivet2OKTorqueJudgment = objReader["Rivet2OKTorqueJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKTorqueJudgment"]),
                        Rivet2OKTorque = objReader["Rivet2OKTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKTorque"]),
                        Rivet2OKPositionJudgment = objReader["Rivet2OKPositionJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKPositionJudgment"]),
                        Rivet2OKPosition = objReader["Rivet2OKPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKPosition"]),
                        Rivet2OverTime = objReader["Rivet2OverTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OverTime"]),
                        Rivet2MaxSpeed = objReader["Rivet2MaxSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2MaxSpeed"]),
                        Rivet3Force = objReader["Rivet3Force"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3Force"]),
                        Rivet3ForceP = objReader["Rivet3ForceP"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3ForceP"]),
                        Rivet3ForceI = objReader["Rivet3ForceI"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3ForceI"]),
                        Rivet3RotationalSpeed = objReader["Rivet3RotationalSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3RotationalSpeed"]),
                        Rivet3RotationalACCTime = objReader["Rivet3RotationalACCTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3RotationalACCTime"]),
                        Rivet3RotationalDECTime = objReader["Rivet3RotationalDECTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3RotationalDECTime"]),
                        Rivet3OKUpPosition = objReader["Rivet3OKUpPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKUpPosition"]),
                        Rivet3OKDownPosition = objReader["Rivet3OKDownPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKDownPosition"]),
                        Rivet3OKSpeedJudgment = objReader["Rivet3OKSpeedJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKSpeedJudgment"]),
                        Rivet3OKSpeed = objReader["Rivet3OKSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKSpeed"]),
                        Rivet3OKPositionVariationJudgment = objReader["Rivet3OKPositionVariationJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKPositionVariationJudgment"]),
                        Rivet3OKPositionVariation = objReader["Rivet3OKPositionVariation"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKPositionVariation"]),
                        Rivet3OKPositionVariationSamplintTime = objReader["Rivet3OKPositionVariationSamplintTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKPositionVariationSamplintTime"]),
                        Rivet3OKTorqueJudgment = objReader["Rivet3OKTorqueJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKTorqueJudgment"]),
                        Rivet3OKTorque = objReader["Rivet3OKTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKTorque"]),
                        Rivet3OKPositionJudgment = objReader["Rivet3OKPositionJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKPositionJudgment"]),
                        Rivet3OKPosition = objReader["Rivet3OKPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKPosition"]),
                        Rivet3OverTime = objReader["Rivet3OverTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OverTime"]),
                        Rivet3MaxSpeed = objReader["Rivet3MaxSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3MaxSpeed"]),

                        Comment = objReader["Comment"].ToString(),




                    });
                }
                objReader.Close();
            }
            catch(Exception ex)
            {


            }
            return list;
        }

        #endregion

        #region 查询PLC工艺号

        public DataSet GetPLC(string id)
        {
            string sql = @"select MultistageId, 
                        TargetVelo1,
                        TargetVelo2,
                        TargetVelo3,
                        TargetVelo4,
                        TargetVelo5,
                        RotationalSpeed1,
                        RotationalSpeed2,
                        RotationalSpeed3,
                        RotationalSpeed4,
                        RotationalSpeed5,
                        TargetPos1,
                        TargetPos2,
                        TargetPos3,
                        TargetPos4,
                        TargetPos5,
                        Bias1,
                        TargetDownforce1,
                        TargetTorque1,
                        T1,
                        FeedVelo1,
                        FeedVelo2,
                
                        MaxPrePressingTime,
                        MaxRivetingTime,
                        UPLimitPos,
                        StopTorque,
                        Constant_Downforce1,
                        PressTime,
                        TargetVelo6,
                        TargetPos6,
                        FeedPos1,
                        FSR_FeedPos1,
                        FSR_ContactPos1,
                        UpperPos1,
                        LowerPos1,
                        StopPressure1,
                        Pre_Downforce1,
                        PrePressureSetValue,
                        PressConfirmed,
                        StopTorqueConfirmed, 
                        PrePressHighPosition,
                        PrePressHighSpeed,
                        PrePressLowPosition,
                        PrePressLowSpeed,
                        PrePressTouchForce,
                        PrePressForce,
                        Rivet1Force,
                        Rivet1ForceP,
                        Rivet1ForceI,
                        Rivet1RotationalSpeed,
                        Rivet1RotationalACCTime,
                        Rivet1RotationalDECTime,
                        Rivet1OKUpPosition,
                        Rivet1OKDownPosition,
                        Rivet1OKSpeedJudgment,
                        Rivet1OKSpeed,
                        Rivet1OKPositionVariationJudgment,
                        Rivet1OKPositionVariation,
                        Rivet1OKPositionVariationSamplintTime,
                        Rivet1OKTorqueJudgment,
                        Rivet1OKTorque,
                        Rivet1OKPositionJudgment,
                        Rivet1OKPosition,
                        Rivet1OverTime,
                        Rivet1MaxSpeed,
                        Rivet2Force,
                        Rivet2ForceP,
                        Rivet2ForceI,
                        Rivet2RotationalSpeed,
                        Rivet2RotationalACCTime,
                        Rivet2RotationalDECTime,
                        Rivet2OKUpPosition,
                        Rivet2OKDownPosition,
                        Rivet2OKSpeedJudgment,
                        Rivet2OKSpeed,
                        Rivet2OKPositionVariationJudgment,
                        Rivet2OKPositionVariation,
                        Rivet2OKPositionVariationSamplintTime,
                        Rivet2OKTorqueJudgment,
                        Rivet2OKTorque,
                        Rivet2OKPositionJudgment,
                        Rivet2OKPosition,
                        Rivet2OverTime,
                        Rivet2MaxSpeed,
                        Rivet3Force,
                        Rivet3ForceP,
                        Rivet3ForceI,
                        Rivet3RotationalSpeed,
                        Rivet3RotationalACCTime,
                        Rivet3RotationalDECTime,
                        Rivet3OKUpPosition,
                        Rivet3OKDownPosition,
                        Rivet3OKSpeedJudgment,
                        Rivet3OKSpeed,
                        Rivet3OKPositionVariationJudgment,
                        Rivet3OKPositionVariation,
                        Rivet3OKPositionVariationSamplintTime,
                        Rivet3OKTorqueJudgment,
                        Rivet3OKTorque,
                        Rivet3OKPositionJudgment,
                        Rivet3OKPosition,
                        Rivet3OverTime,
                        Rivet3MaxSpeed 
                    from Settings where SettingsId = " + id;
            //SqlDataReader objReader = SQLHelper.GetReader(sql);


            DataSet ds = SQLHelper.GetDataSet(sql); 
            return ds;
        }


        #endregion





        #region 工艺导出
        public static DataSet exportFile()
        {
            string sql = @"select  * from Settings"; 
            DataSet ds = SQLHelper.GetDataSet(sql);
            return ds;
        }
        #endregion




        #region 工艺导入
        public static void importFile(string csvFilePath)
        {
 
            
            SettingsService.DeleteSettingsAll();

                using (var csvReader = new TextFieldParser(csvFilePath))
                {
                    csvReader.SetDelimiters(new string[] { "," });
                    csvReader.HasFieldsEnclosedInQuotes = true;
                    // 跳过标题行
                    csvReader.ReadLine();
                while (!csvReader.EndOfData)
                {
                    string[] fields = csvReader.ReadFields();
                    //假设CSV文件有两列数据
                    var value1 = fields[0];
                    var value2 = fields[1];


                    StringBuilder objBuilder = new StringBuilder();
                    objBuilder.Append(@"insert into Settings(SettingsId,TechnicsNumber,SettingsName,FastenerId,LayerStackId,MultistageId,TargetPos1,TargetPos2,TargetPos3,TargetPos4,TargetPos5,TargetVelo1,TargetVelo2,TargetVelo3,TargetVelo4,TargetVelo5,RotationalSpeed1,RotationalSpeed2,RotationalSpeed3,RotationalSpeed4,RotationalSpeed5,Bias1,TargetDownforce1,TargetTorque1,T1,FeedVelo1,FeedVelo2,FSR_FeedPos1,FeedPos1,FSR_ContactPos1,UpperPos1,LowerPos1,StopPressure1,Pre_Downforce1,PrePressureSetValue,PressConfirmed,Constant_Downforce1,PressTime,TargetVelo6,TargetPos6,MaxFeedingTime,MaxPrePressingTime,MaxRivetingTime,StopTorqueConfirmed,UPLimitPos,StopTorque,FastenerName,Para_D,Para_P,Para_H,Para_L,LayerStackName,Material1,Thickness1,Material2,Thickness2,PrePressHighPosition,PrePressHighSpeed,PrePressLowPosition,PrePressLowSpeed,PrePressTouchForce,PrePressForce,Rivet1Force,Rivet1ForceP,Rivet1ForceI,Rivet1RotationalSpeed,Rivet1RotationalACCTime,Rivet1RotationalDECTime,Rivet1OKUpPosition,Rivet1OKDownPosition,Rivet1OKSpeedJudgment,Rivet1OKSpeed,Rivet1OKPositionVariationJudgment,Rivet1OKPositionVariation,Rivet1OKPositionVariationSamplintTime,Rivet1OKTorqueJudgment,Rivet1OKTorque,Rivet1OKPositionJudgment,Rivet1OKPosition,Rivet1OverTime,Rivet1MaxSpeed,Rivet2Force,Rivet2ForceP,Rivet2ForceI,Rivet2RotationalSpeed,Rivet2RotationalACCTime,Rivet2RotationalDECTime,Rivet2OKUpPosition,Rivet2OKDownPosition,Rivet2OKSpeedJudgment,Rivet2OKSpeed,Rivet2OKPositionVariationJudgment,Rivet2OKPositionVariation,Rivet2OKPositionVariationSamplintTime,Rivet2OKTorqueJudgment,Rivet2OKTorque,Rivet2OKPositionJudgment,Rivet2OKPosition,Rivet2OverTime,Rivet2MaxSpeed,Rivet3Force,Rivet3ForceP,Rivet3ForceI,Rivet3RotationalSpeed,Rivet3RotationalACCTime,Rivet3RotationalDECTime,Rivet3OKUpPosition,Rivet3OKDownPosition,Rivet3OKSpeedJudgment,Rivet3OKSpeed,Rivet3OKPositionVariationJudgment,Rivet3OKPositionVariation,Rivet3OKPositionVariationSamplintTime,Rivet3OKTorqueJudgment,Rivet3OKTorque,Rivet3OKPositionJudgment,Rivet3OKPosition,Rivet3OverTime,Rivet3MaxSpeed)");
                    objBuilder.Append(@" values({0},'{1}','{2}','{3}',{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},{27},{28},{29},{30},{31},{32},{33},{34},{35},{36},{37},{38},{39},{40},{41},{42},{43},{44},{45},'{46}',{47},{48},{49},{50},'{51}','{52}',{53},'{54}',{55},{56},{57},{58},{59},{60},{61},{62},{63},{64},{65},{66},{67},{68},{69},{70},{71},{72},{73},{74},{75},{76},{77},{78},{79},{80},{81},{82},{83},{84},{85},{86},{87},{88},{89},{90},{91},{92},{93},{94},{95},{96},{97},{98},{99},{100},{101},{102},{103},{104},{105},{106},{107},{108},{109},{110},{111},{112},{113},{114},{115},{116},{117},{118} )");
                    string sql = string.Format(objBuilder.ToString(),
                                       fields[0], fields[1], fields[2], fields[3], fields[4], fields[5], fields[6], fields[7], fields[8], fields[9], fields[10], fields[11], fields[12], fields[13], fields[14], fields[15], fields[16], fields[17], fields[18], fields[19], fields[20], fields[21], fields[22], fields[23], fields[24], fields[25], fields[26], fields[27], fields[28], fields[29], fields[30], fields[31], fields[32], fields[33], fields[34], fields[35] == "false" ? 0 : 1, fields[36], fields[37], fields[38], fields[39], fields[40], fields[41], fields[42], fields[43] == "false" ? 0 : 1, fields[44], fields[45], fields[46], fields[47], fields[48], fields[49], fields[50], fields[51], fields[52], fields[53], fields[54], fields[55], fields[56], fields[57], fields[58], fields[59], fields[60], fields[61], fields[62], fields[63], fields[64], fields[65], fields[66], fields[67], fields[68], fields[69], fields[70], fields[71], fields[72] == "false" ? 0 : 1, fields[73], fields[74], fields[75] == "false" ? 0 : 1, fields[76], fields[77] == "false" ? 0 : 1, fields[78], fields[79], fields[80], fields[81], fields[82], fields[83], fields[84], fields[85], fields[86], fields[87], fields[88], fields[89], fields[90], fields[91] == "false" ? 0 : 1, fields[92], fields[93], fields[94] == "false" ? 0 : 1, fields[95], fields[96] == "false" ? 0 : 1, fields[97], fields[98], fields[99], fields[100], fields[101], fields[102], fields[103], fields[104], fields[105], fields[106], fields[107], fields[108] == "false" ? 0 : 1, fields[109], fields[110], fields[111], fields[112], fields[113] == "false" ? 0 : 1, fields[114], fields[115] == "false" ? 0 : 1, fields[116], fields[117], fields[118]
                            );
                    //提交到数据库
                    try
                    {
                        SQLHelper.Update(sql);
                        
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("导入失败\r\n" + ex.ToString());
                        throw ex;
                    }
                }

            }

            MessageBox.Show("导入成功\r\n");


        }
        #endregion


        #region 判断当前ID号是否已在数据库存在
        /// <summary>
        /// 判断当前ID号是否已在数据库存在
        /// </summary>
        /// <param name="SettingsId"></param>
        /// <returns></returns>
        public bool IsIdNoExisted(string SettingsId)
        {
            string sql = "select count(*) from Settings where SettingsId ={0}";
            sql = string.Format(sql, SettingsId);
            int result = Convert.ToInt32(SQLHelper.GetSingleResult(sql));
            if (result == 1) return true;
            else return false;
        }
        #endregion

        #region 添加工艺规范
        /// <summary>
        /// 添加工艺规范参数对象信息到数据库
        /// </summary>
        /// <param name="objSettings"></param>
        /// <returns></returns>
        public int AddSettings(Settings objSettings)
        {
            StringBuilder objBuilder = new StringBuilder();
            objBuilder.Append(@"insert into Settings(MultistageId,SettingsName,SettingsId,FastenerId,LayerStackId,TargetVelo1,RotationalSpeed1,TargetPos1,Bias1,TargetDownforce1,TargetTorque1,T1,FeedVelo1,FeedVelo2,TargetVelo2,RotationalSpeed2,TargetPos2,TargetVelo3,RotationalSpeed3,TargetPos3,TargetVelo4,RotationalSpeed4,TargetPos4,TargetVelo5,RotationalSpeed5,TargetPos5,MaxFeedingTime,
                                MaxPrePressingTime,
                                MaxRivetingTime,
                                UPLimitPos,
                                StopTorque,
                                Constant_Downforce1,
                                PressTime,
                                TargetVelo6,
                                TargetPos6,
                                FeedPos1,
                                FSR_FeedPos1,
                                FSR_ContactPos1,
                                UpperPos1,
                                LowerPos1,
                                StopPressure1,
                                Pre_Downforce1,
                                PrePressureSetValue,
                                FastenerName,
                                Para_D,
                                Para_P,
                                Para_H,
                                Para_L,
                                LayerStackName,
                                Material1,
                                Thickness1,
                                Material2,
                                Thickness2,PressConfirmed,StopTorqueConfirmed,
                                    PrePressHighPosition, 
                                    PrePressHighSpeed,
                                    PrePressLowPosition,
                                    PrePressLowSpeed,
                                    PrePressTouchForce,
                                    PrePressForce,
                                    Rivet1Force,
                                    Rivet1ForceP,
                                    Rivet1ForceI,
                                    Rivet1RotationalSpeed,
                                    Rivet1RotationalACCTime,
                                    Rivet1RotationalDECTime,
                                    Rivet1OKUpPosition,
                                    Rivet1OKDownPosition,
                                    Rivet1OKSpeedJudgment,
                                    Rivet1OKSpeed,
                                    Rivet1OKPositionVariationJudgment,
                                    Rivet1OKPositionVariation,
                                    Rivet1OKPositionVariationSamplintTime,
                                    Rivet1OKTorqueJudgment,
                                    Rivet1OKTorque,
                                    Rivet1OKPositionJudgment,
                                    Rivet1OKPosition,
                                    Rivet1OverTime,
                                    Rivet1MaxSpeed,
                                    Rivet2Force,
                                    Rivet2ForceP,
                                    Rivet2ForceI,
                                    Rivet2RotationalSpeed,
                                    Rivet2RotationalACCTime,
                                    Rivet2RotationalDECTime,
                                    Rivet2OKUpPosition,
                                    Rivet2OKDownPosition,
                                    Rivet2OKSpeedJudgment,
                                    Rivet2OKSpeed,
                                    Rivet2OKPositionVariationJudgment,
                                    Rivet2OKPositionVariation,
                                    Rivet2OKPositionVariationSamplintTime,
                                    Rivet2OKTorqueJudgment,
                                    Rivet2OKTorque,
                                    Rivet2OKPositionJudgment,
                                    Rivet2OKPosition,
                                    Rivet2OverTime,
                                    Rivet2MaxSpeed,
                                    Rivet3Force,
                                    Rivet3ForceP,
                                    Rivet3ForceI,
                                    Rivet3RotationalSpeed,
                                    Rivet3RotationalACCTime,
                                    Rivet3RotationalDECTime,
                                    Rivet3OKUpPosition,
                                    Rivet3OKDownPosition,
                                    Rivet3OKSpeedJudgment,
                                    Rivet3OKSpeed,
                                    Rivet3OKPositionVariationJudgment,
                                    Rivet3OKPositionVariation,
                                    Rivet3OKPositionVariationSamplintTime,
                                    Rivet3OKTorqueJudgment,
                                    Rivet3OKTorque,
                                    Rivet3OKPositionJudgment,
                                    Rivet3OKPosition,
                                    Rivet3OverTime,
                                    Rivet3MaxSpeed,
                                    Comment
    )");
            objBuilder.Append(@" values({0},'{1}',{2},'{3}',{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25},{26},
                                {27},
                                {28},
                                {29},
                                {30},
                                {31},
                                {32},
                                {33},
                                {34},
                                {35},
                                {36},
                                {37},
                                {38},
                                {39},
                                {40},
                                {41},
                                {42},
                                '{43}',
                                {44},
                                {45},
                                {46},
                                {47},
                                '{48}',
                                '{49}',
                                {50},
                                '{51}',
                                {52},
                                {53},
                                {54}, 
                                  {55},
                                 {56},
                                 {57},
                                 {58},
                                 {59},
                                 {60},
                                 {61},
                                 {62},
                                 {63},
                                 {64},
                                 {65},
                                 {66},
                                 {67},
                                 {68},
                                 {69},
                                 {70},
                                 {71},
                                 {72},
                                 {73},
                                 {74},
                                 {75},
                                 {76},
                                 {77},
                                 {78},
                                 {79},
                                 {80},
                                 {81},
                                 {82},
                                 {83},
                                 {84},
                                 {85},
                                 {86},
                                 {87},
                                 {88},
                                 {89},
                                 {90},
                                 {91},
                                 {92},
                                 {93},
                                 {94},
                                 {95},
                                 {96},
                                 {97},
                                 {98},
                                 {99},
                                 {100},
                                 {101},
                                 {102},
                                 {103},
                                 {104},
                                 {105},
                                 {106},
                                 {107},
                                 {108},
                                 {109},
                                 {110},
                                 {111},
                                 {112},
                                 {113},
                                 {114},
                                 {115},
                                 {116},
                                 {117}, '{118}'  
                                )");
            string sql = string.Format(objBuilder.ToString(),
                 objSettings.MultistageId,
                //objSettings.SettingsName,
                 objSettings.FastenerName + "-" + objSettings.Material1 + "_" + objSettings.Thickness1 + "+" + objSettings.Material2 + "_" + objSettings.Thickness2 + "-M" + objSettings.MultistageId.ToString().PadLeft(2,'0'),
                objSettings.SettingsId, objSettings.FastenerId, objSettings.LayerStackId,
                objSettings.TargetVelo1, objSettings.RotationalSpeed1, objSettings.TargetPos1, objSettings.Bias1,
                objSettings.TargetDownforce1, objSettings.TargetTorque1, objSettings.T1,objSettings.FeedVelo1,objSettings.FeedVelo2,
                objSettings.TargetVelo2, objSettings.RotationalSpeed2, objSettings.TargetPos2, 
                objSettings.TargetVelo3, objSettings.RotationalSpeed3, objSettings.TargetPos3,
                objSettings.TargetVelo4, objSettings.RotationalSpeed4, objSettings.TargetPos4,
                objSettings.TargetVelo5, objSettings.RotationalSpeed5, objSettings.TargetPos5,objSettings.MaxFeedingTime
                    ,objSettings.MaxPrePressingTime
                    ,objSettings.MaxRivetingTime
                    ,objSettings.UPLimitPos
                    ,objSettings.StopTorque
                    ,objSettings.Constant_Downforce1
                    ,objSettings.PressTime
                    ,objSettings.TargetVelo6
                    ,objSettings.TargetPos6
                    ,objSettings.FeedPos1
                    ,objSettings.FSR_FeedPos1
                    ,objSettings.FSR_ContactPos1
                    ,objSettings.UpperPos1
                    ,objSettings.LowerPos1
                    ,objSettings.StopPressure1
                    ,objSettings.Pre_Downforce1
                    ,objSettings.PrePressureSetValue
                    ,objSettings.FastenerName
                    ,objSettings.Para_D
                    ,objSettings.Para_P
                    ,objSettings.Para_H
                    ,objSettings.Para_L
                    ,objSettings.Material1 + "_" + objSettings.Thickness1 + "+" + objSettings.Material2 + "_" + objSettings.Thickness2
                    ,objSettings.Material1
                    ,objSettings.Thickness1
                    ,objSettings.Material2
                    ,objSettings.Thickness2
                    ,(objSettings.PressConfirmed == false ? 0 : 1)
                    ,(objSettings.StopTorqueConfirmed == false ? 0 : 1)


                    , objSettings.PrePressHighPosition
                    , objSettings.PrePressHighSpeed
                    , objSettings.PrePressLowPosition
                    , objSettings.PrePressLowSpeed
                    , objSettings.PrePressTouchForce
                    , objSettings.PrePressForce
                    , objSettings.Rivet1Force
                    , objSettings.Rivet1ForceP
                    , objSettings.Rivet1ForceI
                    , objSettings.Rivet1RotationalSpeed
                    , objSettings.Rivet1RotationalACCTime
                    , objSettings.Rivet1RotationalDECTime
                    , objSettings.Rivet1OKUpPosition
                    , objSettings.Rivet1OKDownPosition
                    , objSettings.Rivet1OKSpeedJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKSpeed
                    , objSettings.Rivet1OKPositionVariationJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKPositionVariation
                    , objSettings.Rivet1OKPositionVariationSamplintTime
                    , objSettings.Rivet1OKTorqueJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKTorque
                    , objSettings.Rivet1OKPositionJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKPosition
                    , objSettings.Rivet1OverTime
                    , objSettings.Rivet1MaxSpeed
                    , objSettings.Rivet2Force
                    , objSettings.Rivet2ForceP
                    , objSettings.Rivet2ForceI
                    , objSettings.Rivet2RotationalSpeed
                    , objSettings.Rivet2RotationalACCTime
                    , objSettings.Rivet2RotationalDECTime
                    , objSettings.Rivet2OKUpPosition
                    , objSettings.Rivet2OKDownPosition
                    , objSettings.Rivet2OKSpeedJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKSpeed
                    , objSettings.Rivet2OKPositionVariationJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKPositionVariation
                    , objSettings.Rivet2OKPositionVariationSamplintTime
                    , objSettings.Rivet2OKTorqueJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKTorque
                    , objSettings.Rivet2OKPositionJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKPosition
                    , objSettings.Rivet2OverTime
                    , objSettings.Rivet2MaxSpeed
                    , objSettings.Rivet3Force
                    , objSettings.Rivet3ForceP
                    , objSettings.Rivet3ForceI
                    , objSettings.Rivet3RotationalSpeed
                    , objSettings.Rivet3RotationalACCTime
                    , objSettings.Rivet3RotationalDECTime
                    , objSettings.Rivet3OKUpPosition
                    , objSettings.Rivet3OKDownPosition
                    , objSettings.Rivet3OKSpeedJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKSpeed
                    , objSettings.Rivet3OKPositionVariationJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKPositionVariation
                    , objSettings.Rivet3OKPositionVariationSamplintTime
                    , objSettings.Rivet3OKTorqueJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKTorque
                    , objSettings.Rivet3OKPositionJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKPosition
                    , objSettings.Rivet3OverTime
                    , objSettings.Rivet3MaxSpeed
                      , objSettings.Comment








                    );
            //提交到数据库
            try
            {
                return SQLHelper.Update(sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion


        public List<Settings> GetSearch(string vname)
        {
            string sql = "";// SettingsName like '%" + vname + "%'";

            if(vname == "") 
                sql = "select * from Settings";
            else
                sql = "select * from Settings where  SettingsId =  '" + vname + "'";
            SqlDataReader objReader = SQLHelper.GetReader(sql);
            List<Settings> list = new List<Settings>();
            while (objReader.Read())
            {
                list.Add(new Settings()
                {
                    MultistageId = Convert.ToInt32(objReader["MultistageId"]),
                    SettingsId = Convert.ToInt32(objReader["SettingsId"]),
                    SettingsName = Convert.ToString(objReader["SettingsName"]),

         

                    FastenerId = Convert.ToString(objReader["FastenerId"]),
                    LayerStackId = Convert.ToInt32(objReader["LayerStackId"]),
                    TargetVelo1 = Convert.ToSingle(objReader["TargetVelo1"]),
                    TargetVelo2 = Convert.ToSingle(objReader["TargetVelo2"]),
                    TargetVelo3 = Convert.ToSingle(objReader["TargetVelo3"]),
                    TargetVelo4 = Convert.ToSingle(objReader["TargetVelo4"]),
                    TargetVelo5 = Convert.ToSingle(objReader["TargetVelo5"]),
                    RotationalSpeed1 = Convert.ToSingle(objReader["RotationalSpeed1"]),
                    RotationalSpeed2 = Convert.ToSingle(objReader["RotationalSpeed2"]),
                    RotationalSpeed3 = Convert.ToSingle(objReader["RotationalSpeed3"]),
                    RotationalSpeed4 = Convert.ToSingle(objReader["RotationalSpeed4"]),
                    RotationalSpeed5 = Convert.ToSingle(objReader["RotationalSpeed5"]),
                    TargetPos1 = Convert.ToSingle(objReader["TargetPos1"]),
                    TargetPos2 = Convert.ToSingle(objReader["TargetPos2"]),
                    TargetPos3 = Convert.ToSingle(objReader["TargetPos3"]),
                    TargetPos4 = Convert.ToSingle(objReader["TargetPos4"]),
                    TargetPos5 = Convert.ToSingle(objReader["TargetPos5"]),
                    Bias1 = Convert.ToSingle(objReader["Bias1"]),
                    TargetDownforce1 = Convert.ToSingle(objReader["TargetDownforce1"]),
                    TargetTorque1 = Convert.ToSingle(objReader["TargetTorque1"]),
                    T1 = Convert.ToSingle(objReader["T1"]),
                    FeedVelo1 = Convert.ToSingle(objReader["FeedVelo1"]),
                    FeedVelo2 = Convert.ToSingle(objReader["FeedVelo2"]),

                    MaxFeedingTime = Convert.ToInt32(objReader["MaxFeedingTime"]),
                    MaxPrePressingTime = Convert.ToInt32(objReader["MaxPrePressingTime"]),
                    MaxRivetingTime = Convert.ToInt32(objReader["MaxRivetingTime"]),
                    UPLimitPos = Convert.ToSingle(objReader["UPLimitPos"]),
                    StopTorque = Convert.ToSingle(objReader["StopTorque"]),
                    Constant_Downforce1 = Convert.ToSingle(objReader["Constant_Downforce1"]),
                    PressTime = Convert.ToInt32(objReader["PressTime"]),
                    TargetVelo6 = Convert.ToSingle(objReader["TargetVelo6"]),
                    TargetPos6 = Convert.ToSingle(objReader["TargetPos6"]),
                    FeedPos1 = Convert.ToSingle(objReader["FeedPos1"]),
                    FSR_FeedPos1 = Convert.ToSingle(objReader["FSR_FeedPos1"]),
                    FSR_ContactPos1 = Convert.ToSingle(objReader["FSR_ContactPos1"]),
                    UpperPos1 = Convert.ToSingle(objReader["UpperPos1"]),
                    LowerPos1 = Convert.ToSingle(objReader["LowerPos1"]),
                    StopPressure1 = Convert.ToSingle(objReader["StopPressure1"]),
                    Pre_Downforce1 = Convert.ToSingle(objReader["Pre_Downforce1"]),
                    PrePressureSetValue = Convert.ToSingle(objReader["PrePressureSetValue"]),
                    FastenerName = Convert.ToString(objReader["FastenerName"]),
                    Para_D = Convert.ToString(objReader["Para_D"]),
                    Para_P = Convert.ToString(objReader["Para_P"]),
                    Para_H = Convert.ToString(objReader["Para_H"]),
                    Para_L = Convert.ToString(objReader["Para_L"]),
                    LayerStackName = Convert.ToString(objReader["LayerStackName"]),
                    Material1 = Convert.ToString(objReader["Material1"]),
                    Thickness1 = Convert.ToString(objReader["Thickness1"]),
                    Material2 = Convert.ToString(objReader["Material2"]),
                    Thickness2 = Convert.ToString(objReader["Thickness2"]), 
                    PressConfirmed = Convert.ToBoolean(objReader["PressConfirmed"]),
                    StopTorqueConfirmed = Convert.ToBoolean(objReader["StopTorqueConfirmed"]),






                    PrePressHighPosition = objReader["PrePressHighPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressHighPosition"]),
                    PrePressHighSpeed = objReader["PrePressHighSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressHighSpeed"]),
                    PrePressLowPosition = objReader["PrePressLowPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressLowPosition"]),
                    PrePressLowSpeed = objReader["PrePressLowSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressLowSpeed"]),
                    PrePressTouchForce = objReader["PrePressTouchForce"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressTouchForce"]),
                    PrePressForce = objReader["PrePressForce"].ToString() == "" ? 0 : Convert.ToSingle(objReader["PrePressForce"]),
                    Rivet1Force = objReader["Rivet1Force"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1Force"]),
                    Rivet1ForceP = objReader["Rivet1ForceP"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1ForceP"]),
                    Rivet1ForceI = objReader["Rivet1ForceI"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1ForceI"]),
                    Rivet1RotationalSpeed = objReader["Rivet1RotationalSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1RotationalSpeed"]),
                    Rivet1RotationalACCTime = objReader["Rivet1RotationalACCTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1RotationalACCTime"]),
                    Rivet1RotationalDECTime = objReader["Rivet1RotationalDECTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1RotationalDECTime"]),
                    Rivet1OKUpPosition = objReader["Rivet1OKUpPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKUpPosition"]),
                    Rivet1OKDownPosition = objReader["Rivet1OKDownPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKDownPosition"]),
                    Rivet1OKSpeedJudgment = objReader["Rivet1OKSpeedJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKSpeedJudgment"]),
                    Rivet1OKSpeed = objReader["Rivet1OKSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKSpeed"]),
                    Rivet1OKPositionVariationJudgment = objReader["Rivet1OKPositionVariationJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKPositionVariationJudgment"]),
                    Rivet1OKPositionVariation = objReader["Rivet1OKPositionVariation"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKPositionVariation"]),
                    Rivet1OKPositionVariationSamplintTime = objReader["Rivet1OKPositionVariationSamplintTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKPositionVariationSamplintTime"]),
                    Rivet1OKTorqueJudgment = objReader["Rivet1OKTorqueJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKTorqueJudgment"]),
                    Rivet1OKTorque = objReader["Rivet1OKTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKTorque"]),
                    Rivet1OKPositionJudgment = objReader["Rivet1OKPositionJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet1OKPositionJudgment"]),
                    Rivet1OKPosition = objReader["Rivet1OKPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OKPosition"]),
                    Rivet1OverTime = objReader["Rivet1OverTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1OverTime"]),
                    Rivet1MaxSpeed = objReader["Rivet1MaxSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet1MaxSpeed"]),
                    Rivet2Force = objReader["Rivet2Force"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2Force"]),
                    Rivet2ForceP = objReader["Rivet2ForceP"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2ForceP"]),
                    Rivet2ForceI = objReader["Rivet2ForceI"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2ForceI"]),
                    Rivet2RotationalSpeed = objReader["Rivet2RotationalSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2RotationalSpeed"]),
                    Rivet2RotationalACCTime = objReader["Rivet2RotationalACCTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2RotationalACCTime"]),
                    Rivet2RotationalDECTime = objReader["Rivet2RotationalDECTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2RotationalDECTime"]),
                    Rivet2OKUpPosition = objReader["Rivet2OKUpPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKUpPosition"]),
                    Rivet2OKDownPosition = objReader["Rivet2OKDownPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKDownPosition"]),
                    Rivet2OKSpeedJudgment = objReader["Rivet2OKSpeedJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKSpeedJudgment"]),
                    Rivet2OKSpeed = objReader["Rivet2OKSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKSpeed"]),
                    Rivet2OKPositionVariationJudgment = objReader["Rivet2OKPositionVariationJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKPositionVariationJudgment"]),
                    Rivet2OKPositionVariation = objReader["Rivet2OKPositionVariation"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKPositionVariation"]),
                    Rivet2OKPositionVariationSamplintTime = objReader["Rivet2OKPositionVariationSamplintTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKPositionVariationSamplintTime"]),
                    Rivet2OKTorqueJudgment = objReader["Rivet2OKTorqueJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKTorqueJudgment"]),
                    Rivet2OKTorque = objReader["Rivet2OKTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKTorque"]),
                    Rivet2OKPositionJudgment = objReader["Rivet2OKPositionJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet2OKPositionJudgment"]),
                    Rivet2OKPosition = objReader["Rivet2OKPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OKPosition"]),
                    Rivet2OverTime = objReader["Rivet2OverTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2OverTime"]),
                    Rivet2MaxSpeed = objReader["Rivet2MaxSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet2MaxSpeed"]),
                    Rivet3Force = objReader["Rivet3Force"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3Force"]),
                    Rivet3ForceP = objReader["Rivet3ForceP"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3ForceP"]),
                    Rivet3ForceI = objReader["Rivet3ForceI"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3ForceI"]),
                    Rivet3RotationalSpeed = objReader["Rivet3RotationalSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3RotationalSpeed"]),
                    Rivet3RotationalACCTime = objReader["Rivet3RotationalACCTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3RotationalACCTime"]),
                    Rivet3RotationalDECTime = objReader["Rivet3RotationalDECTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3RotationalDECTime"]),
                    Rivet3OKUpPosition = objReader["Rivet3OKUpPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKUpPosition"]),
                    Rivet3OKDownPosition = objReader["Rivet3OKDownPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKDownPosition"]),
                    Rivet3OKSpeedJudgment = objReader["Rivet3OKSpeedJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKSpeedJudgment"]),
                    Rivet3OKSpeed = objReader["Rivet3OKSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKSpeed"]),
                    Rivet3OKPositionVariationJudgment = objReader["Rivet3OKPositionVariationJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKPositionVariationJudgment"]),
                    Rivet3OKPositionVariation = objReader["Rivet3OKPositionVariation"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKPositionVariation"]),
                    Rivet3OKPositionVariationSamplintTime = objReader["Rivet3OKPositionVariationSamplintTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKPositionVariationSamplintTime"]),
                    Rivet3OKTorqueJudgment = objReader["Rivet3OKTorqueJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKTorqueJudgment"]),
                    Rivet3OKTorque = objReader["Rivet3OKTorque"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKTorque"]),
                    Rivet3OKPositionJudgment = objReader["Rivet3OKPositionJudgment"].ToString() == "" ? false : Convert.ToBoolean(objReader["Rivet3OKPositionJudgment"]),
                    Rivet3OKPosition = objReader["Rivet3OKPosition"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OKPosition"]),
                    Rivet3OverTime = objReader["Rivet3OverTime"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3OverTime"]),
                    Rivet3MaxSpeed = objReader["Rivet3MaxSpeed"].ToString() == "" ? 0 : Convert.ToSingle(objReader["Rivet3MaxSpeed"]),









                });
            }
            objReader.Close();
            return list;
        }



        #region 更新工艺规范,不可更改编号
        /// <summary>
        /// 更新工艺规范信息到数据库
        /// </summary>
        /// <param name="objSettings"></param>
        /// <returns></returns>
        public int ModifySettings(Settings objSettings)
        {
            StringBuilder objBuilder = new StringBuilder();
            objBuilder.Append(@"Update Settings set SettingsName='{0}',SettingsId={1},FastenerId='{2}',LayerStackId={3},TargetVelo1={4},RotationalSpeed1={5},TargetPos1={6},Bias1={7},TargetDownforce1={8},TargetTorque1={9},T1={10},FeedVelo1={11},FeedVelo2={12}");
            objBuilder.Append(@" ,MultistageId={13},TargetVelo2={14},RotationalSpeed2={15},TargetPos2={16},TargetVelo3={17},RotationalSpeed3={18},TargetPos3={19},TargetVelo4={20},RotationalSpeed4={21},TargetPos4={22},TargetVelo5={23},RotationalSpeed5={24},TargetPos5={25},MaxFeedingTime={26},
                            MaxPrePressingTime={27},
                            MaxRivetingTime={28},
                            UPLimitPos={29},
                            StopTorque={30},
                            Constant_Downforce1={31},
                            PressTime={32},
                            TargetVelo6={33},
                            TargetPos6={34},
                            FeedPos1={35},
                            FSR_FeedPos1={36},
                            FSR_ContactPos1={37},
                            UpperPos1={38},
                            LowerPos1={39},
                            StopPressure1={40},
                            Pre_Downforce1={41},
                            PrePressureSetValue={42},
                            FastenerName='{43}',
                            Para_D={44},
                            Para_P={45},
                            Para_H={46},
                            Para_L ={47},
                            LayerStackName='{48}',
                            Material1='{49}',
                            Thickness1={50},
                            Material2='{51}',
                            Thickness2={52},
                            PressConfirmed={53},
                            StopTorqueConfirmed={54},


                            PrePressHighPosition = {55} ,
                            PrePressHighSpeed = {56} ,
                            PrePressLowPosition = {57} ,
                            PrePressLowSpeed = {58} ,
                            PrePressTouchForce = {59} ,
                            PrePressForce = {60} ,
                            Rivet1Force = {61} ,
                            Rivet1ForceP = {62} ,
                            Rivet1ForceI = {63} ,
                            Rivet1RotationalSpeed = {64} ,
                            Rivet1RotationalACCTime = {65} ,
                            Rivet1RotationalDECTime = {66} ,
                            Rivet1OKUpPosition = {67} ,
                            Rivet1OKDownPosition = {68} ,
                            Rivet1OKSpeedJudgment = {69} ,
                            Rivet1OKSpeed = {70} ,
                            Rivet1OKPositionVariationJudgment = {71} ,
                            Rivet1OKPositionVariation = {72} ,
                            Rivet1OKPositionVariationSamplintTime = {73} ,
                            Rivet1OKTorqueJudgment = {74} ,
                            Rivet1OKTorque = {75} ,
                            Rivet1OKPositionJudgment = {76} ,
                            Rivet1OKPosition = {77} ,
                            Rivet1OverTime = {78} ,
                            Rivet1MaxSpeed = {79} ,
                            Rivet2Force = {80} ,
                            Rivet2ForceP = {81} ,
                            Rivet2ForceI = {82} ,
                            Rivet2RotationalSpeed = {83} ,
                            Rivet2RotationalACCTime = {84} ,
                            Rivet2RotationalDECTime = {85} ,
                            Rivet2OKUpPosition = {86} ,
                            Rivet2OKDownPosition = {87} ,
                            Rivet2OKSpeedJudgment = {88} ,
                            Rivet2OKSpeed = {89} ,
                            Rivet2OKPositionVariationJudgment = {90} ,
                            Rivet2OKPositionVariation = {91} ,
                            Rivet2OKPositionVariationSamplintTime = {92} ,
                            Rivet2OKTorqueJudgment = {93} ,
                            Rivet2OKTorque = {94} ,
                            Rivet2OKPositionJudgment = {95} ,
                            Rivet2OKPosition = {96} ,
                            Rivet2OverTime = {97} ,
                            Rivet2MaxSpeed = {98} ,
                            Rivet3Force = {99} ,
                            Rivet3ForceP = {100} ,
                            Rivet3ForceI = {101} ,
                            Rivet3RotationalSpeed = {102} ,
                            Rivet3RotationalACCTime = {103} ,
                            Rivet3RotationalDECTime = {104} ,
                            Rivet3OKUpPosition = {105} ,
                            Rivet3OKDownPosition = {106} ,
                            Rivet3OKSpeedJudgment = {107} ,
                            Rivet3OKSpeed = {108} ,
                            Rivet3OKPositionVariationJudgment = {109} ,
                            Rivet3OKPositionVariation = {110} ,
                            Rivet3OKPositionVariationSamplintTime = {111} ,
                            Rivet3OKTorqueJudgment = {112} ,
                            Rivet3OKTorque = {113} ,
                            Rivet3OKPositionJudgment = {114} ,
                            Rivet3OKPosition = {115} ,
                            Rivet3OverTime = {116} ,
                            Rivet3MaxSpeed = {117},
                            Comment = '{118}'

                            ");
            objBuilder.Append(" where SettingsId={119}");
            string sql = string.Format(objBuilder.ToString(),
                //objSettings.SettingsName,

                  objSettings.FastenerName + "-" + objSettings.Material1 + "_" + objSettings.Thickness1 + "+" + objSettings.Material2 + "_" + objSettings.Thickness2 + "-M" + objSettings.MultistageId.ToString().PadLeft(2, '0'),

                objSettings.SettingsId, objSettings.FastenerId, objSettings.LayerStackId,
                objSettings.TargetVelo1, objSettings.RotationalSpeed1, objSettings.TargetPos1, objSettings.Bias1,
                objSettings.TargetDownforce1, objSettings.TargetTorque1, objSettings.T1, objSettings.FeedVelo1, objSettings.FeedVelo2,
                objSettings.MultistageId,
                objSettings.TargetVelo2, objSettings.RotationalSpeed2, objSettings.TargetPos2,
                objSettings.TargetVelo3, objSettings.RotationalSpeed3, objSettings.TargetPos3,
                objSettings.TargetVelo4, objSettings.RotationalSpeed4, objSettings.TargetPos4,
                objSettings.TargetVelo5, objSettings.RotationalSpeed5, objSettings.TargetPos5,
                objSettings.MaxFeedingTime
                    ,objSettings.MaxPrePressingTime
                    ,objSettings.MaxRivetingTime
                    ,objSettings.UPLimitPos
                    ,objSettings.StopTorque
                    ,objSettings.Constant_Downforce1
                    ,objSettings.PressTime
                    ,objSettings.TargetVelo6
                    ,objSettings.TargetPos6
                    ,objSettings.FeedPos1
                    ,objSettings.FSR_FeedPos1
                    ,objSettings.FSR_ContactPos1
                    ,objSettings.UpperPos1
                    ,objSettings.LowerPos1
                    ,objSettings.StopPressure1
                    ,objSettings.Pre_Downforce1
                    ,objSettings.PrePressureSetValue
                    ,objSettings.FastenerName
                    ,objSettings.Para_D
                    ,objSettings.Para_P
                    ,objSettings.Para_H
                    ,objSettings.Para_L
                    , objSettings.Material1+"_"+ objSettings.Thickness1+"+"+ objSettings.Material2 + "_" + objSettings.Thickness2//objSettings.LayerStackName
                    , objSettings.Material1
                    ,objSettings.Thickness1
                    ,objSettings.Material2
                    ,objSettings.Thickness2
                    ,(objSettings.PressConfirmed == false ? 0 : 1 )
                    ,(objSettings.StopTorqueConfirmed == false ? 0 : 1)

                    , objSettings.PrePressHighPosition
                    , objSettings.PrePressHighSpeed
                    , objSettings.PrePressLowPosition
                    , objSettings.PrePressLowSpeed
                    , objSettings.PrePressTouchForce
                    , objSettings.PrePressForce
                    , objSettings.Rivet1Force
                    , objSettings.Rivet1ForceP
                    , objSettings.Rivet1ForceI
                    , objSettings.Rivet1RotationalSpeed
                    , objSettings.Rivet1RotationalACCTime
                    , objSettings.Rivet1RotationalDECTime
                    , objSettings.Rivet1OKUpPosition
                    , objSettings.Rivet1OKDownPosition
                    , objSettings.Rivet1OKSpeedJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKSpeed
                    , objSettings.Rivet1OKPositionVariationJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKPositionVariation
                    , objSettings.Rivet1OKPositionVariationSamplintTime
                    , objSettings.Rivet1OKTorqueJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKTorque
                    , objSettings.Rivet1OKPositionJudgment == false ? 0 : 1
                    , objSettings.Rivet1OKPosition
                    , objSettings.Rivet1OverTime
                    , objSettings.Rivet1MaxSpeed
                    , objSettings.Rivet2Force
                    , objSettings.Rivet2ForceP
                    , objSettings.Rivet2ForceI
                    , objSettings.Rivet2RotationalSpeed
                    , objSettings.Rivet2RotationalACCTime
                    , objSettings.Rivet2RotationalDECTime
                    , objSettings.Rivet2OKUpPosition
                    , objSettings.Rivet2OKDownPosition
                    , objSettings.Rivet2OKSpeedJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKSpeed
                    , objSettings.Rivet2OKPositionVariationJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKPositionVariation
                    , objSettings.Rivet2OKPositionVariationSamplintTime
                    , objSettings.Rivet2OKTorqueJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKTorque
                    , objSettings.Rivet2OKPositionJudgment == false ? 0 : 1
                    , objSettings.Rivet2OKPosition
                    , objSettings.Rivet2OverTime
                    , objSettings.Rivet2MaxSpeed
                    , objSettings.Rivet3Force
                    , objSettings.Rivet3ForceP
                    , objSettings.Rivet3ForceI
                    , objSettings.Rivet3RotationalSpeed
                    , objSettings.Rivet3RotationalACCTime
                    , objSettings.Rivet3RotationalDECTime
                    , objSettings.Rivet3OKUpPosition
                    , objSettings.Rivet3OKDownPosition
                    , objSettings.Rivet3OKSpeedJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKSpeed
                    , objSettings.Rivet3OKPositionVariationJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKPositionVariation
                    , objSettings.Rivet3OKPositionVariationSamplintTime
                    , objSettings.Rivet3OKTorqueJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKTorque
                    , objSettings.Rivet3OKPositionJudgment == false ? 0 : 1
                    , objSettings.Rivet3OKPosition
                    , objSettings.Rivet3OverTime
                    , objSettings.Rivet3MaxSpeed
                      , objSettings.Comment

                    , objSettings.EidtId);
            //提交到数据库
            try
            {
                return SQLHelper.Update(sql);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region 删除工艺规范
        /// <summary>
        /// 删除工艺规范信息到数据库
        /// </summary>
        /// <param name="settingsId"></param>
        /// <returns></returns>
        public int DeleteSettingsById(string settingsId)
        {
            string sql = "delete from Settings where SettingsId=" + settingsId;
            //提交到数据库
            try
            {
                return SQLHelper.Update(sql);
            }
            catch (SqlException ex)
            {
                if (ex.Number == 547)
                    throw new Exception("该工艺规范被其他数据表引用，不能直接删除该工艺规范对象！");
                else
                    throw new Exception("数据库操作出现异常！具体信息：" + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion




        #region 删除所有工艺规范
        /// <summary>
        /// 删除工艺规范信息到数据库
        /// </summary>
        /// <param name="settingsId"></param>
        /// <returns></returns>
        public static int DeleteSettingsAll()
        {
            string sql = "delete from Settings";
            //提交到数据库
            try
            {
                return SQLHelper.Update(sql);
            }
            catch (SqlException ex)
            {
                if (ex.Number == 547)
                    throw new Exception("该工艺规范被其他数据表引用，不能直接删除该工艺规范对象！");
                else
                    throw new Exception("数据库操作出现异常！具体信息：" + ex.Message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

    }
}
